package com.mad.game.system;

public class Vector2 {

	public static enum Axis {
		X, Y ; 
	}
	
	public static final Vector2 NULL_VECTOR = new  Vector2(0, 0);
	
	private int x, y ;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	} 
	
	public Vector2(int x, int y) {
		this.setX(x);
		this.setY(y);
	}

	public void changeXByDelta(int dx){
		this.x += dx ; 
	}
	
	public void changeYByDelta(int dy){
		this.y += dy ; 
	}	
	
	public Vector2 invert(){
		return new Vector2(-x, -y);
	}
	
	public Vector2 divide(int factor){
		return new Vector2(x / factor, y / factor); 
	}
	
	public boolean isGreaterThan(Axis axis, int value){
		switch(axis){
		case X: return this.x > value ; 
		case Y: return this.y > value ; 
		}
		return false ; 
	}
	public boolean isLessThan(Axis axis, int value){
		switch(axis){
		case X: return this.x < value ; 
		case Y: return this.y < value ; 
		}
		return false ; 
	}
	public boolean isGreaterThanOrEqual(Axis axis, int value){
		switch(axis){
		case X: return this.x >= value ; 
		case Y: return this.y >= value ; 
		}
		return false ; 
	}
	public boolean isLessThanOrEqual(Axis axis, int value){
		switch(axis){
		case X: return this.x <= value ; 
		case Y: return this.y <= value ; 
		}
		return false ; 
	}

	public Vector2 createCopy(){
		return new Vector2(this.x, this.y); 
	}
	
	public Vector2 transformToUnitVector(){
		int tx = this.x != 0 ? this.x / (int)Math.abs(this.x) : 0 ; 
		int ty = this.y != 0 ? this.y / (int)Math.abs(this.y) : 0 ;  
		return new Vector2(tx, ty);
	}
	
	@Override
	public boolean equals(Object obj) {
		return obj != null && obj instanceof Vector2 && 
			((Vector2)obj).x == this.x && ((Vector2)obj).y == this.y ; 
	}
	
	@Override
	public String toString() {
		return "Vector2: [ x: "+this.x+", y: "+this.y+" ]";
	}
	
}

